import 'package:flutter_mvp/contact/contact.dart';
import 'package:flutter_mvp/contact/data/contact_data.dart';
import 'package:flutter_mvp/contact/data/contact_data_impl.dart';

//
// Created by StephenChen on 2018/4/3.
//
// Presenter 接口的实现，协调model和view
//
class ContactPresenter implements Presenter {
  ContactRepository _repository;
  View _view;

  ContactPresenter(this._view) : assert(_view != null) {
    _view.setPresenter(this);
  }

  @override
  init() {
    _repository = new Injector().getContactRepository(RepositoryType.mock);
  }

  @override
  loadContacts() {
    _repository.fetch().then((contacts) {
      _view.onLoadContactsComplete(contacts);
    }).catchError((error) {
      _view.onLoadContactsError(error);
    });
  }
}
